/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-SDL2/specific/view/draw_game_playing.h"
#include "PlanetWars2dRT-SDL2/specific/view/draw_game.h"
#include "PlanetWars2dRT-SDL2/specific/view/draw_game_state.h"
#include "PlanetWars2dRT-SDL2/specific/controller/game_playing_data.h"
#include "PlanetWars2dRT-SDL2/utils/SDL.h"


EXTERN_C_BEGIN


bool
SDL_draw_game_playing(game_playing_t* a_game_playing)
{
  game_playing_data_sdl* data = (game_playing_data_sdl*) a_game_playing->data;
  SDL_SetRenderDrawColor(data->main_window_renderer,
			 BACKGROUND_DEFAULT_COLOR_RED,
			 BACKGROUND_DEFAULT_COLOR_GREEN,
			 BACKGROUND_DEFAULT_COLOR_BLUE,
			 BACKGROUND_DEFAULT_COLOR_ALPHA);
  SDL_RenderClear(data->main_window_renderer);
  
  if(!SDL_draw_vector_game(data->main_window_renderer,
			   &a_game_playing->game,
			   stderr, true)
     ||
     !SDL_draw_game_state(data->main_window_renderer,
			  &a_game_playing->state,
			  stderr))
    {
      SDL_DestroyRenderer(data->main_window_renderer);
      SDL_and_main_window_quit(data->main_window);
      game_playing_destructor(a_game_playing);
      return false;
    }
  SDL_RenderPresent(data->main_window_renderer);
  
  return true;
}


EXTERN_C_END
